<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
            / abc /: /表示边界符，有转移的效果
        */

        const rg = /a/;

        /* 
            开始符号和结束符号的限制
            需求：：以xxx开始，或者以xxx结束
            ^: 匹配输入的开始
            $: 匹配输入的结束
        */
        const rg1 = /^a/;//代表以a为开头的字符
        console.log(rg1.test("abc"));   //true
        console.log(rg1.test("aabc"));  //true
        console.log(rg1.test("bcd"));   //false
        console.log(rg1.test("bac"));   //false
        console.log("-----------------------------");

        const rg2 = /^a...b$/;//代表以a开头跟以b结尾
        console.log(rg2.test("abbc"));  //false
        console.log(rg2.test("aabbc"));  //false
        console.log(rg2.test("abba"));   //false
        console.log(rg2.test("baab"));   //false
        console.log(rg2.test("abab"));   //true
        console.log(rg2.test("abaab"));   //true

        /* 
            . 默认匹配除了换行符以外的任何单个字符
        */
        console.log("================================");
        const rg3 = /^a.b$/;//代表以a开头以b结尾中间可以是任何字符
        console.log(rg3.test("abbc"));
        console.log(rg3.test("aabbc"));
        console.log(rg3.test("aba"));
        console.log(rg3.test("bab"));
        console.log(rg3.test("asb"));   //true
        console.log(rg3.test("ascb"));   
    </script>
</body>

</html>